#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
using ll = int64_t;

const ll maxn = 1500+5;
ll n,r[maxn],d[maxn],q,ans,cnt[maxn][maxn];
char c[maxn][maxn];

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            std::cin>>c[i][j];
        }
        std::cin>>r[i];
    }
    for(ll i=1;i<=n;i++){
        std::cin>>d[i];
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            ll x=i,y=j;
            while(x<=n && y<=n){
                cnt[x][y]++;
                ll nx = x+(c[x][y]=='D'), ny = y+(c[x][y]=='R');
                x=nx,y=ny;
            }
            // printf("%lld, %lld add %lld\n",i,j,x>n?d[y]:r[x]);
            ans+= x>n?d[y]:r[x];
        }
    }
    // for(ll i=1;i<=n;i++){
    //     for(ll j=1;j<=n;j++){
    //         printf("%lld ",cnt[i][j]);
    //     }
    //     printf("\n");
    // }
    // printf("\n");
    std::cin>>q;
    std::cout<<ans<<"\n";
    while(q--){
        ll i,j;
        std::cin>>i>>j;
        ll x=i,y=j;
        x+=c[i][j]=='D';
        y+=c[i][j]=='R';
        while(x<=n && y<=n){
            cnt[x][y]-=cnt[i][j];
            ll nx = x+(c[x][y]=='D'), ny = y+(c[x][y]=='R');
                x=nx,y=ny;
        }
        ans-=cnt[i][j]*(x>n?d[y]:r[x]);
        // printf("tmp ans=%lld\n",ans);
        c[i][j]=c[i][j]=='R'?'D':'R';
        x=i,y=j;
        x+=c[i][j]=='D';
        y+=c[i][j]=='R';
        while(x<=n && y<=n){
            cnt[x][y]+=cnt[i][j];
            ll nx = x+(c[x][y]=='D'), ny = y+(c[x][y]=='R');
                x=nx,y=ny;
        }
        // printf("x=%lld, y=%lld\n",x,y);
        ans+=cnt[i][j]*(x>n?d[y]:r[x]);
        std::cout<<ans<<"\n";
        // for(ll i=1;i<=n;i++){
        //     for(ll j=1;j<=n;j++){
        //         printf("%c ",c[i][j]);
        //     }
        //     printf("\n");
        // }
        // printf("\n");
    }
}